<template>
	<view class="parent-view">
		<view style="background-color: #F5F6FA;width: 100%;height: 20rpx;"></view>
		<view class="top-view">
			<view class="book-view">
				<image class="book-cover" src="../../static/icon-manager-book-cover.png" mode="scaleToFill"></image>
				<text class="jiapu-tuijina-txt" v-if="treeData.info.look_auth==1||treeData.info.look_auth==2" @click="tuijianClick">点击推荐</text>
				<text class="jiapu-tuijina-txt" v-else @click="tuijianClick">取消推荐</text>
			</view>
			<view class="content-view">
				<text class="book-title">{{treeData.info.title}}</text>
				<text class="book-faqi">发起人：{{jiapuInfo.uname}}</text>
				<text class="book-faqi" style="margin-top: 14rpx;">家谱号：{{treeData.info.coding}}</text>
				<text class="book-faqi" style="margin-top: 14rpx;">所属地区：{{jiapuAddress}}</text>
				<text class="book-faqi"style="margin-top: 14rpx;">创建时间：{{jiapuInfo.createtime}}</text>
			</view>
			<view class="gdb-view" v-if="treeData.info.jpmuseumid" @click="hongbaoClick">
				<image class="gdb-icon" src="../../static/icon_gongdebang_hongbao.png"/>
				<text class="gdb-text">功德榜</text>
			</view>
		</view>
		<view style="background-color: #F5F6FA;width: 100%;height: 20rpx;"></view>
		<view class="book-item" @click="jiaPuNameClick">
			<text class="item-title">家谱名称</text>
			<text style="flex: 1;"/>
			<text class="item-content">{{treeData.info.title}}</text>
			<image class="item-arrow" src="../../static/right-arrow.png"></image>
		</view>
		<view class="book-item" @click="addressClick">
			<text class="item-title">所属地区</text>
			<text style="flex: 1;"/>
			<text class="item-content">{{jiapuAddress}}</text>
			<image class="item-arrow" src="../../static/right-arrow.png"></image>
		</view>
		<view class="book-item" @click="jiaPuDescClick">
			<text class="item-title">家谱简介</text>
			<text style="flex: 1;"/>
			<text class="item-content">{{treeData.info.bio}}</text>
			<image class="item-arrow" src="../../static/right-arrow.png"></image>
		</view>
		<view class="book-item" @click="managerMember">
			<text class="item-title">管理成员</text>
			<text style="flex: 1;"/>
			<text class="item-content">设置管理权限</text>
			<image class="item-arrow" src="../../static/right-arrow.png"></image>
		</view>
		<view  v-if="jiapuCount>1" style="background-color: #F5F6FA;width: 100%;height: 20rpx;"></view>
		<view v-if="jiapuCount>1" class="book-item" @click="tuichu">
			<text class="item-title">退出家谱</text>
		</view>
		<view  v-if="jiapuCount>1"  style="background-color: #F5F6FA;width: 100%;height: 20rpx;"></view>
		<inputTBDalog :isShow="isShowTuiJian" :dataSource="dialogData"  @returnInputDialog="returnTuiJian"/>
		<outTreeDialog :isShow="isShowTuiChu" :dataSource="dialogTuiChuData"  @returnOutTreeDialog="returnTuiChu"/>
		<inputDalog :isShow="isJiaPuTitleShow" :dataSource="nameData" @returnInputDialog="inputJiaPuNameReturn"/>
		<inputJiaPuDescDalog :isShow="isShowDescPop" :dataSource="treeData.info.bio" @returnInputDesc="inputJiaPuDescReturn"/>
		<choseAddress :isShow="isChoseAddressShow" @returnAddress="addressReturn"/>
	</view>
</template>

<script>
	import request from '../index/request.js';
	import inputTBDalog from '../../components/tip-two-btn-dialog/tip-two-btn-dialog.vue'
	import outTreeDialog from '../../components/out-tree-dialog/out-tree-dialog.vue'
	import inputDalog from '../../components/input-dialog/input-dialog.vue'
	import inputJiaPuDescDalog from '../../components/input-jiapu-desc-dialog/input-jiapu-desc-dialog.vue'
	import choseAddress from '../../components/chose-address/chose-address.vue'
	
	export default {
		components: {
			inputTBDalog,inputDalog,inputJiaPuDescDalog,choseAddress,outTreeDialog
		},
		data() {
			return {
				treeId:"",
				treeData:null,
				jiapuInfo:{},
				isShowTuiJian:false,
				isJiaPuTitleShow:false,
				isShowDescPop:false,
				isChoseAddressShow:false,
				isShowTuiChu:false,
				jiapuAddress:"",
				dialogTuiChuData:{
					title:"温馨提示",
					content:"您确定要退出家谱吗？",
					leftTxt:"取消",
					rightTxt:"确定",
					tag:"tuichu",
				},
				dialogData:{
					title:"温馨提示",
					content:"",
					leftTxt:"取消",
					rightTxt:"确定",
					tag:"zhiye",
				},
				nameData:{
					title:"修改家谱名称",
					hint:"请输入家谱名称",
					leftTxt:"取消",
					rightTxt:"确定",
					tag:"jiapuName",
				},
				jiapuCount:1,
			}
		},
		onLoad:function(){
			this.jiapuInfo=uni.getStorageSync("jiapu_click_data")
			this.treeId=this.jiapuInfo.id
			this.jiapuAddress=this.jiapuInfo.area
			this.jiapuCount=uni.getStorageSync("shiqin-user-jiapu-count")
			this.getTreeData()
		},
		methods: {
			onShow:function(){
				this.share.url='/pages/tabBar/home/index?appInviteId='+this.appUtil.getAppInviteId()
				this.share.shareType=1
			},
			getTreeData:function(){
				var that=this
				request.post("api/apiv2/GetTree",{
					TreeId:that.treeId
				}).then(data=>{
					that.treeData=data
				})
			},
			tuichu:function(){
				this.isShowTuiChu=true
			},
			returnTuiChu:function(event){
				this.isShowTuiChu=event.isclose
				if(event.tag){
					this.outTree()
				}
			},
			hongbaoClick:function(){
				uni.navigateTo({
					url:"../../pagesA/qualities-list-home/index?treeid="+this.treeId+"&treeCode="+this.treeData.info.coding
				})
			},
			addressClick:function(){
				this.isChoseAddressShow=true
			},
			addressReturn:function(event){
				this.isChoseAddressShow=event.isclose
				if(event.address){
					this.jiapuAddress=event.address
					this.setTreeAIS("area",event.address)
				}
			},
			jiaPuNameClick:function(){
				this.isJiaPuTitleShow=true
			},
			inputJiaPuNameReturn:function(event){
				this.isJiaPuTitleShow=event.isclose
				if(event.tag&&event.inputStr){
					this.setTreeAIS("title",event.inputStr)
				}
			},
			jiaPuDescClick:function(){
				this.isShowDescPop=true
			},
			inputJiaPuDescReturn:function(event){
				this.isShowDescPop=event.isclose
				if(event.tag&&event.inputStr){
					this.setTreeAIS("bio",event.inputStr)
				}
			},
			tuijianClick:function(){
				if(this.treeData.info.look_auth==1||this.treeData.info.look_auth==2){
					this.dialogData.content="是否推荐到家谱展览"
				}else{
					this.dialogData.content="是否取消家谱展览"
				}
				this.isShowTuiJian=true
			},
			returnTuiJian:function(event){
				this.isShowTuiJian=event.isclose
				if(event.tag){
					if(this.treeData.info.look_auth==1||this.treeData.info.look_auth==2){
						this.setTreeAIS("auth","0")
					}else{
						this.setTreeAIS("auth","2")
					}
				}
			},
			outTree:function(key,value){
				var that=this
				request.post("api/apiv2/OutTree",{
					TreeId:that.treeId,
				}).then(data=>{
					uni.navigateBack({
						delta:2
					})
				})
			},
			setTreeAIS:function(key,value){
				var that=this
				request.post("api/apiv2/SetTreeAIS",{
					TreeId:that.treeId,
					SetKey:key,
					SetVal:value
				}).then(data=>{
					that.getTreeData()
				})
			},
			managerMember:function(){
				uni.navigateTo({
					url:"../manager-member/index"
				})
			},
		}
	}
</script>

<style>
	@import "index.css";
</style>
